namespace Org.Loon.Framework.Xna.Game.Action
{

    using Org.Loon.Framework.Xna.Game.Core.Timer;
    using Org.Loon.Framework.Xna.Game.Core.Graphics.Component;

    public abstract class ActionEvent
    {

        private LTimer timer;

        private ActionListener actionListener;

        internal bool firstTick, isComplete, isInit;

        internal Actor original;

        internal object tag;

        internal float offsetX, offsetY;

        public ActionEvent()
        {
            timer = new LTimer(0);
        }

        public virtual long GetDelay()
        {
            return timer.GetDelay();
        }

        public virtual void SetDelay(long d)
        {
            timer.SetDelay(d);
        }

        public virtual void Paused(bool pause)
        {
            ActionControl.GetInstance().Paused(pause, original);
        }

        public virtual void Step(long elapsedTime)
        {
            if (original == null)
            {
                return;
            }
            if (timer.Action(elapsedTime))
            {
                if (firstTick)
                {
                    this.firstTick = false;
                    this.timer.Refresh();
                }
                else
                {
                    Update(elapsedTime);
                }
                if (actionListener != null)
                {
                    actionListener.Process(original);
                }
            }
        }

        public virtual object GetOriginal()
        {
            return original;
        }

        public virtual void Start(Actor o)
        {
            if (o == null)
            {
                return;
            }
            this.original = o;
            this.timer.Refresh();
            this.firstTick = true;
            this.isComplete = false;
            this.isInit = false;
            if (actionListener != null)
            {
                actionListener.Start(o);
            }
        }

        public abstract void Update(long elapsedTime);

        public abstract void OnLoad();

        public virtual void Stop()
        {
            if (actionListener != null)
            {
                actionListener.Stop(original);
            }
        }

        public abstract bool IsComplete();

        public virtual object GetTag()
        {
            return tag;
        }

        public virtual void SetTag(object t)
        {
            this.tag = t;
        }

        public virtual void SetComplete(bool c)
        {
            this.isComplete = c;
        }

        public virtual ActionListener GetActionListener()
        {
            return actionListener;
        }

        public virtual void SetActionListener(ActionListener a)
        {
            this.actionListener = a;
        }

        public virtual void SetOffset(float x, float y)
        {
            this.offsetX = x;
            this.offsetY = y;
        }

        public virtual float GetOffsetX()
        {
            return offsetX;
        }

        public virtual void SetOffsetX(float x)
        {
            this.offsetX = x;
        }

        public virtual float GetOffsetY()
        {
            return offsetY;
        }

        public virtual void SetOffsetY(float y)
        {
            this.offsetY = y;
        }
    }
}
